﻿#ifndef CONTROLLED_H
#define CONTROLLED_H

#include <QObject>
#include <QDebug>
#include "operation.h"
#include "description.h"
#include "ledcontroller.h"
#include <QJsonObject>

typedef struct _tagWordopSubCmd{
    // 命令码
    unsigned char cmd;
    // 通道号
    unsigned char channel;
    // 命令参数
    unsigned char data;
}WORDOPSUBCMD;

typedef struct _tagWordopCmd{
    // 标识符
    unsigned char identifier;
    // 长度
    unsigned char len;
    // 设备型号
    unsigned char code;
    // 设备ID
    unsigned char id;
    // 命令
    WORDOPSUBCMD    wordopSubCmd;
    // 其他命令(s)
    WORDOPSUBCMD*   pWordopSubCmds;
    // 校验和
    unsigned char chksum;
}WORDOPCMD;

class WordopControlLEDOperation : public Operation
{
    Q_OBJECT
public:
    explicit WordopControlLEDOperation(QObject *parent = nullptr);

private:
    int             m_nChannel;
    int             m_nValue;
    WORDOPCMD       m_nWordopCMD;

    Description*    m_pDescription;

private:
    QByteArray  ConvertCMD2Bytes(WORDOPCMD& wordopcmd);
    void PrepareCMD();
    void ChkSum(WORDOPCMD& wordopcmd);

public:
    virtual void run() override;
    virtual void writeXML(QXmlStreamWriter& writer) override;
    virtual void readFromXML(QXmlStreamReader& reader) override;

    virtual QString getClassName() override;

public:
    int nChannel() const;
    void setNChannel(int newNChannel);
    int nValue() const;
    void setNValue(int newNValue);
};

#endif // CONTROLLED_H
